﻿#include "stdafx.h"
#include "Car.h"
#include "PassengerCar.h"
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
using namespace std;

// по содержимому данного файла вообще отдельный разговор =)
int main(int argc, _TCHAR* argv[])
{
	bool b1 = true;
	bool b2 = true;
	bool b3 = true;
	string name, command;
	char fileName[50];
	int i;
	vector <Car> Cars;
	cout << "Please enter name of file" << endl;
	cin >> fileName;
	ifstream fin(fileName);
	if (!fin)
	{
		cout << "Error open file " << fileName << endl;
		exit(1);
	} 
	while (!fin.eof())
	{
		fin >> name;
		fin >> i;
		Cars.push_back(PassengerCar(name, (i == 1) ? true : false));
	}
	while (b3)
	{
        // изучить: приведение типов.
        // warning при сравнении разных типов.
		for (i = 0; i < Cars.size(); i++)
		{
			cout << i + 1 << ") ";
			Cars[i].PrintBrand();
			cout << endl;
		}
		cout << "Please enter auto(enter nubmer of auto)" << endl;
		cin >> i;
		b1 = true;
		while (b1)
		{
			b2 = true;
			cout << "Enter your command(forward, back, left, right, stop, beep)" << endl;
			cin >> command;
			Cars[i-1].Control(command);
			cout << "Next command? (yes/no)" << endl;
			cin >> name;
			while (b2)
			{
				if (name == "yes")
				{
					b1 = true;
					b2 = false;
				}
				else if (name == "no")
				{			
					b1 = false;
					b2 = false;
				}
				else
				{
					cout << "Please enter 'yes' or 'no'" << endl;
					cin >> name;
				}
			}
		}
		cout << "Continue? (yes/no)" << endl;
		cin >> name;
		b2 = true;
		while (b2)
		{
			if (name == "yes")
			{
				b3 = true;
				b2 = false;
			}
			else if (name == "no")
			{			
				b3 = false;
				b2 = false;
			}
			else
			{
				cout << "Please enter 'yes' or 'no'" << endl;
				cin >> name;
			}
		}
	}
	return 0;
}

